package com.diudiutechnology.www.yadiudiu.yadiudiu.singlecall.MyActivity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.diudiutechnology.www.yadiudiu.R;
import com.diudiutechnology.www.yadiudiu.util.utils.Constant;

import java.util.List;

/**
 * Created by admin on 2017/9/27.
 */

public class DetailsCreditAdapter extends BaseAdapter {
    private Context mContext;
    private List<CreditDetailBean> mDetailBean;

    public DetailsCreditAdapter(Context context, List<CreditDetailBean> beanList) {
        this.mContext = context;
        this.mDetailBean = beanList;
    }

    @Override
    public int getCount() {
        return mDetailBean.size();
    }

    @Override
    public Object getItem(int position) {
        return mDetailBean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        Holder holder = null;
        if (convertView == null) {
            holder = new Holder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.layout_cridet_item, null);
            holder.imageView = (ImageView) convertView.findViewById(R.id.bg);
            holder.textView = (TextView) convertView.findViewById(R.id.text);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        CreditDetailBean bean = mDetailBean.get(position);
        if (bean.is_pic.equals("2")) {
            holder.textView.setVisibility(View.GONE);
            holder.imageView.setVisibility(View.VISIBLE);
            Glide.with(mContext).load(Constant.HTTP + bean.text).into(holder.imageView);
        } else {
            holder.textView.setVisibility(View.VISIBLE);
            holder.imageView.setVisibility(View.GONE);
            holder.textView.setText(bean.text);
        }
        return convertView;
    }

    class Holder {
        TextView textView;
        ImageView imageView;
    }
}
